Micron Document
🎖️GitЯра🎖️

Node / meshtastic / Meshtastic-Android / files / androidApp / src / google / kotlin / org / meshtastic / app / map / tiles / MapTileHttpClient.kt

Displaying Raw • Download

androidApp/src/google/kotlin/org/meshtastic/app/map/tiles/MapTileHttpClient.kt renovate/fastlane-2.x-lockfile (056eed64) Text, 3.78 KB

T8b949e/*
* Copyright (c) 2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
Tff7b72package T7ee787org.meshtastic.app.map.tiles

Tff7b72import T7ee787android.content.Context
Tff7b72import T7ee787okhttp3.Cache
Tff7b72import T7ee787okhttp3.Interceptor
Tff7b72import T7ee787okhttp3.OkHttpClient
Tff7b72import T7ee787org.koin.core.annotation.Single
Tff7b72import T7ee787org.meshtastic.core.common.BuildConfigProvider
Tff7b72import T7ee787java.io.File

T8b949e/** Roughly a few thousand tiles — enough that panning around a working area stops re-downloading. */
Tff7b72private Tff7b72const Tff7b72val Te6edf3TILE_CACHE_BYTES Tff7b72= T79c0ff6T79c0ff4L Tff7b72* T79c0ff1T79c0ff0T79c0ff2T79c0ff4 Tff7b72* T79c0ff1T79c0ff0T79c0ff2T79c0ff4

T8b949e/**
* An hour is long enough that scrolling never re-fetches, and short enough that a time-varying layer like weather radar
* cannot go badly stale behind it.
*/
Tff7b72private Tff7b72const Tff7b72val Te6edf3FALLBACK_MAX_AGE_SECONDS Tff7b72= T79c0ff6T79c0ff0 Tff7b72* T79c0ff6T79c0ff0

T8b949e/**
* The client raster map tiles are fetched through, and the disk cache that makes panning cheap.
*
* Deliberately separate from the app's shared Ktor client: tiles would evict API responses from a shared cache, and
* they want a far larger budget than anything else the app fetches.
*/
Tf0883e@Single
Tff7b72class T56d364MapTileHttpClientTb4b4b4(Tff7b72private Tff7b72val Te6edf3contextTb4b4b4: Te6edf3ContextTb4b4b4, Tff7b72private Tff7b72val Te6edf3buildConfigTb4b4b4: Te6edf3BuildConfigProviderTb4b4b4) Tb4b4b4{

T8b949e/** Built on first use: nothing needs a tile cache until a raster source is actually selected. */
Tff7b72val Te6edf3clientTb4b4b4: Te6edf3OkHttpClient Tff7b72by Te6edf3lazy Tb4b4b4{
Te6edf3OkHttpClientTb4b4b4.Te6edf3BuilderTb4b4b4(Tb4b4b4)
Tb4b4b4.Te6edf3cacheTb4b4b4(Te6edf3CacheTb4b4b4(Te6edf3FileTb4b4b4(Te6edf3contextTb4b4b4.Te6edf3cacheDirTb4b4b4, Ta5d6ff"Ta5d6ffmap-tilesTa5d6ff"Tb4b4b4)Tb4b4b4, Te6edf3TILE_CACHE_BYTESTb4b4b4)Tb4b4b4)
Tb4b4b4.Te6edf3addNetworkInterceptorTb4b4b4(Te6edf3FallbackCachePolicyTb4b4b4)
Tb4b4b4.Te6edf3addInterceptorTb4b4b4(Te6edf3IdentifyingUserAgentTb4b4b4(Te6edf3buildConfigTb4b4b4)Tb4b4b4)
Tb4b4b4.Te6edf3buildTb4b4b4(Tb4b4b4)
Tb4b4b4}
Tb4b4b4}

T8b949e/**
* Names the app on every tile request.
*
* OpenStreetMap's tile usage policy requires an identifying User-Agent and blocks clients that send a generic library
* default, which `okhttp/x.y` is. The OSMdroid map this replaces set the same requirement through its tile source
* policy flags; nothing carried it over when the fetch moved to OkHttp.
*/
Tff7b72private Tff7b72class T56d364IdentifyingUserAgentTb4b4b4(Tff7b72private Tff7b72val Te6edf3buildConfigTb4b4b4: Te6edf3BuildConfigProviderTb4b4b4) Tb4b4b4: Te6edf3Interceptor Tb4b4b4{
Tff7b72override Tff7b72fun Td2a8ffinterceptTb4b4b4(Te6edf3chainTb4b4b4: Te6edf3InterceptorTb4b4b4.Te6edf3ChainTb4b4b4)Tb4b4b4: Te6edf3okhttp3Tb4b4b4.Te6edf3Response Tff7b72= Te6edf3chainTb4b4b4.Te6edf3proceedTb4b4b4(
Te6edf3chain
Tb4b4b4.Te6edf3requestTb4b4b4(Tb4b4b4)
Tb4b4b4.Te6edf3newBuilderTb4b4b4(Tb4b4b4)
Tb4b4b4.Te6edf3headerTb4b4b4(Ta5d6ff"Ta5d6ffUser-AgentTa5d6ff"Tb4b4b4, Ta5d6ff"Ta5d6ffMeshtastic-Android/Tffd700${Te6edf3buildConfigTb4b4b4.Te6edf3versionNameTffd700}Ta5d6ff (Tffd700${Te6edf3buildConfigTb4b4b4.Te6edf3applicationIdTffd700}Ta5d6ff)Ta5d6ff"Tb4b4b4)
Tb4b4b4.Te6edf3buildTb4b4b4(Tb4b4b4)Tb4b4b4,
Tb4b4b4)
Tb4b4b4}

T8b949e/**
* Supplies a cache lifetime for tile servers that state none.
*
* The servers we ship all send `Cache-Control` or `Expires` and are left alone. A custom source the user typed in is
* often a plain file server that sends neither, and OkHttp will not cache a response it was told nothing about — which
* would leave exactly the wipe-while-scrolling this cache exists to fix.
*/
Tff7b72private Tff7b72object T56d364FallbackCachePolicy Tb4b4b4: Te6edf3Interceptor Tb4b4b4{
Tff7b72override Tff7b72fun Td2a8ffinterceptTb4b4b4(Te6edf3chainTb4b4b4: Te6edf3InterceptorTb4b4b4.Te6edf3ChainTb4b4b4)Tb4b4b4: Te6edf3okhttp3Tb4b4b4.Te6edf3Response Tb4b4b4{
Tff7b72val Te6edf3response Tff7b72= Te6edf3chainTb4b4b4.Te6edf3proceedTb4b4b4(Te6edf3chainTb4b4b4.Te6edf3requestTb4b4b4(Tb4b4b4)Tb4b4b4)
Tff7b72val Te6edf3serverStatedPolicy Tff7b72= Te6edf3responseTb4b4b4.Te6edf3headerTb4b4b4(Ta5d6ff"Ta5d6ffCache-ControlTa5d6ff"Tb4b4b4) Tff7b72!Tff7b72= Tff7b72null Tff7b72|Tff7b72| Te6edf3responseTb4b4b4.Te6edf3headerTb4b4b4(Ta5d6ff"Ta5d6ffExpiresTa5d6ff"Tb4b4b4) Tff7b72!Tff7b72= Tff7b72null
Tff7b72return Tff7b72if Tb4b4b4(Te6edf3serverStatedPolicyTb4b4b4) Tb4b4b4{
Te6edf3response
Tb4b4b4} Tff7b72else Tb4b4b4{
Te6edf3responseTb4b4b4.Te6edf3newBuilderTb4b4b4(Tb4b4b4)Tb4b4b4.Te6edf3headerTb4b4b4(Ta5d6ff"Ta5d6ffCache-ControlTa5d6ff"Tb4b4b4, Ta5d6ff"Ta5d6ffpublic, max-age=Tffd700$Te6edf3FALLBACK_MAX_AGE_SECONDSTa5d6ff"Tb4b4b4)Tb4b4b4.Te6edf3buildTb4b4b4(Tb4b4b4)
Tb4b4b4}
Tb4b4b4}
Tb4b4b4}

Served by rngit 1.5.2 - Generated in 0.05s